<template>
  <div class="aside-collapse-container">
    <div>
      <div class="aside-collapse-header">
        <span>{{title}}</span>
        <div>
	        <i
		        v-if="!hideSort"
		        :class="!isSorting ? 'el-icon-sort' : 'el-icon-finished'"
		        class="aside-collapse-icon mar-rgt-10" @click="sortWidget"></i>
          <i
	          v-if="!hideOperation"
	          class="el-icon-plus aside-collapse-icon mar-rgt-10"
	          @click="addPage"></i>
          <i
	          :class="collapse ? 'el-icon-caret-right' : 'el-icon-caret-bottom'"
	          class="font-size-20"
	          @click="collapse = !collapse"></i>
        </div>
      </div>
      <div v-show="!collapse" class="aside-collapse-content">
        <slot name="default"></slot>
      </div>
    </div>
  </div>
</template>

<script>
  import {messageHandle} from "@/utils";

  export default {
    name: 'AsideCollapse',
    props: {
      title: {
        type: String,
        default: ''
      },
      hideOperation: {
        type: Boolean,
        default: false
      },
	    hideSort: {
        type: Boolean,
        default: false
      },
    },
    data() {
      return {
        collapse: false,
	      isSorting: false,
      };
    },
    methods: {
      addPage() {
        this.$emit('addPage');
      },
	    sortWidget() {
				this.isSorting = !this.isSorting;
				if (this.isSorting) {
					messageHandle({type: 'success', msg: `组件树已进入排序模式`});
				} else {
					messageHandle({type: 'success', msg: `组件树已完成排序`});
				}
		    this.$emit('sort', this.isSorting);
	    }
    }
  };
</script>

<style scoped lang="less">
  .aside-collapse-container {

    .aside-collapse-header {
      display: flex;
      justify-content: space-between;
      padding: 0 10px;
      color: #12131A;
      font-size: 16px;
      font-weight: bold;
      background: #fff;
      border-bottom: 1px #DADCE5 solid;
      border-top: 1px #DADCE5 solid;
      height: 50px;
      align-items: center;
      box-sizing: border-box;

	    .aside-collapse-icon {
		    font-size: 16px;
		    cursor: pointer;

		    &:hover {
			    color: @colorPrimary;
			    font-weight: bold;
		    }
	    }
    }

    .aside-collapse-content {
      padding: 10px;

      .aside-collapse-item {
        width: 50px;
        height: 50px;
        object-fit: contain;
        cursor: pointer;
        padding: 3px;
        margin: 3px;
      }

      &::-webkit-scrollbar {
        display: none;
      }
    }
  }
</style>
